﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;


namespace T33
{
    class Program
    {
        private static int gamesID;
        private static int gamesName;
        private static object gamesPrice;
        private static int gamesCount;

        static void Main(string[] args)
        {
            string sql = "select gamesID,gamesName,gamesPrice,gamesCount from games";
            SqlDataReader dr = DBHelper.Reader(sql);
            Console.WriteLine("序号\t游戏名称\t游戏价格\t库存数量");
            Console.WriteLine("*******************************************************************");
            while (dr.Read())
            {
                string gamesID = dr["gamesID"].ToString();
                string gamesName = dr["gamesName"].ToString();
                string gamesPrice = dr["gamesPrice"].ToString();
                string gamesCount = dr["gamesCount"].ToString();
                Console.WriteLine("{0}\t{1}\t{2}\t\t{3}", gamesID, gamesName, gamesPrice, gamesCount);
            }
            string sql2 = "insert into games(gamesName,gamesPrice,gamesCount) values('我的世界','50','100')";
            bool result = DBHelper.NonQuery(sql2);
            if (result)
            {
                Console.WriteLine("添加成功！！");
            }
            else
            {
                Console.WriteLine("添加失败！！");
            }
            string sql3 = "select sum(gamesPrice*gamesCount) from games";
            Console.WriteLine("游戏总金额：{0}", DBHelper.Scalar(sql3));
        }
    }
}
